package com.osce.go_score.controller;

import com.csce.domain.entity.go_score.GoScoreExExamMark;
import com.csce.domain.entity.go_score.bo.GoScoreExMarkScoreExcelBo;
import com.doudou.core.lang.ObjUtil;
import com.osce.common.annotation.Log;
import com.osce.common.core.controller.BaseController;
import com.osce.common.core.entity.AjaxResult;
import com.osce.common.core.page.TableDataInfo;
import com.osce.common.enums.BusinessType;
import com.osce.common.utils.poi.ExcelUtil;
import com.osce.interfaces.go_score.IGoScoreExExamMarkService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 妇产科考试考场学生-分数Controller
 *
 * @author zzx
 * @since 2024-05-17
 */
@RestController
@RequestMapping("/go_score/go_score_ex_exam_mark")
public class GoScoreExExamMarkController extends BaseController {

    @Resource
    private IGoScoreExExamMarkService goScoreExExamMarkService;

    /**
     * 查询妇产科考试考场学生-分数列表
     */
    @PreAuthorize("@ss.hasPermi('go_score:go_score_ex_exam_mark:list')")
    @GetMapping("/list")
    public TableDataInfo list(GoScoreExExamMark goScoreExExamMark) {
        startPage();
        List<GoScoreExExamMark> list = goScoreExExamMarkService.selectGoScoreExExamMarkList(goScoreExExamMark);
        return getDataTable(list);
    }

    /**
     * 导出妇产科考试考场学生-分数列表
     */
    @PreAuthorize("@ss.hasPermi('system:mark:export')")
    @Log(title = "妇产科考试考场学生-分数", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GoScoreExExamMark goScoreExExamMark) {
        List<GoScoreExMarkScoreExcelBo> goScoreExMarkScoreExcelBos = goScoreExExamMarkService.exportGoScoreExExamMarkList(goScoreExExamMark);
        ExcelUtil<GoScoreExMarkScoreExcelBo> excelUtil = new ExcelUtil<GoScoreExMarkScoreExcelBo>(GoScoreExMarkScoreExcelBo.class);
        try{
            excelUtil.exportExcel(response,goScoreExMarkScoreExcelBos,"成绩单");
        }catch (Exception e){
            logger.error(e.getMessage());
        }
    }


    /**
     * 获取妇产科考试考场学生-分数详细信息
     */
    @PreAuthorize("@ss.hasPermi('go_score:go_score_ex_exam_mark:query')")
    @GetMapping()
    public AjaxResult getInfo(GoScoreExExamMark goScoreExExamMark) {
        return success(goScoreExExamMarkService.selectGoScoreExExamMark(goScoreExExamMark));
    }

    /**
     * 新增妇产科考试考场学生-分数
     */
    @PreAuthorize("@ss.hasPermi('go_score:go_score_ex_exam_mark:add')")
    @Log(title = "妇产科考试考场学生-分数", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoScoreExExamMark goScoreExExamMark) {
        return toAjax(goScoreExExamMarkService.insertGoScoreExExamMark(goScoreExExamMark));
    }

    /**
     * 修改妇产科考试考场学生-分数
     */
    @PreAuthorize("@ss.hasPermi('go_score:go_score_ex_exam_mark:edit')")
    @Log(title = "妇产科考试考场学生-分数", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoScoreExExamMark goScoreExExamMark) {
        goScoreExExamMark = goScoreExExamMarkService.updateGoScoreExExamMark(goScoreExExamMark);
        return AjaxResult.ifSuccess(ObjUtil.isNotNull(goScoreExExamMark),"提交成功","提交失败").data(goScoreExExamMark);
    }

    /**
     * 删除妇产科考试考场学生-分数
     */
    @PreAuthorize("@ss.hasPermi('go_score:go_score_ex_exam_mark:remove')")
    @Log(title = "妇产科考试考场学生-分数", businessType = BusinessType.DELETE)
    @DeleteMapping("/{examIds}")
    public AjaxResult remove(@PathVariable Long[] examIds) {
        return toAjax(goScoreExExamMarkService.deleteGoScoreExExamMarkByExamIds(examIds));
    }
}
